"""
    @Author  ：思念 
    @File    ：4.获取协程中的返回值.py
    @Date    ：2024/12/28 18:57 
"""
import aiohttp
import asyncio


url = 'https://www.baidu.com'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36'
}

def callback(future):
    print(future.result())

async def get_baidu():
    async with aiohttp.ClientSession() as session:
        async with session.get(url=url, headers=headers) as response:
            response = await response.text()
            print(response)

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    tasks = [loop.create_task(get_baidu()) for _ in range(10)]
    # for task in tasks:
    #     task.add_done_callback(callback)
    # loop.run_until_complete(asyncio.wait(tasks))
    loop.run_until_complete(asyncio.gather(*tasks))


